<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>取药</title>
		<link rel="stylesheet" href="layui/css/layui.css" media="all">
	</head>
	<body>
		<fieldset class="table-search-fieldset">
		    <legend>搜索信息</legend>
				<div style="margin: 10px 10px 10px 10px">
					<!-- 查询框 -->
					<form class="layui-form layui-form-pane layui-inline" style="width: 600px;">
						<div class="layui-inline">
							<label class="layui-form-label">药品名</label>
							<div class="layui-input-block">
							  <input type="text" name="medName" lay-verify="required" placeholder="请输入药品名" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit=""  lay-filter="demo1">查询</button>
							</div>
						</div>
					</form>
				</div>
		</fieldset>
		
		
		<table class="layui-hide" id="test" lay-filter="test"></table>
		
		<!-- 操作栏 -->
		<script type="text/html" id="barDemo">
		  <a class="layui-btn layui-btn-xs" lay-event="getMedicine">取药</a>
		</script>
		
		<script src="js/jquery-3.4.1.js"></script>
		<script src="layui/layui.js"></script>
		<script>
			layui.use(['table','form'], function(){
			  var table = layui.table,
			  form=layui.form;
			  
			  table.render({
			    elem: '#test'
			    ,url:'http://localhost:8081/query/queryMedicineByName'
			    ,toolbar: '#toolbarDemo'
			    ,title: '药品表'
				,id:'medTable'
			    ,cols: [[
			      {field:'medId', title:'药品编号', width:90, fixed: 'left', unresize: true}
			      ,{field:'medName', title:'药品名', width:120}
			      ,{field:'medIngredient', title:'成分', width:90}
			      ,{field:'medCharacter', title:'性状', width:100}
			      ,{field:'medEffect', title:'功效'}
			      ,{field:'medPrice', title:'药品价格', width:100}
			      ,{field:'medStorage', title:'库存量', width:100}
			      ,{field:'factoryId', title:'药厂编号', width:100}
			      ,{field:'medProDate', title:'生产日期', width:120}
			      ,{field:'medUseDate', title:'有效期', width:120}
			      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:80}
			    ]]
			    ,page: true
			  });
			  
			  // 监听搜索操作
			  form.on('submit(demo1)', function (data) {
				  // layer.alert(JSON.stringify(data.field), {
				  //   title: '最终的提交信息'
				  // });
	  
					//执行搜索重载
					table.reload('medTable', {
						page: {
							curr: 1
						}
						, where: {
							medName : data.field.medName
						}
					}, 'data');
					            
				  return false;
			  });
			  
			  //取药操作监听
			  table.on('tool(test)', function(obj){
			    //layer.alert(111)
				var data = obj.data;
				//layer.alert(data.id);
				var index = layer.open({
					title: '取药',
					type: 2,
					shade: 0.2,
					maxmin:true,
					shadeClose: true,
					area: ['50%', '50%'],
					content: './getMedDo.html',
					success: function(layero, index){
						var body = layui.layer.getChildFrame('body', index);
						 body.find("#medId").val(data.medId);
					}	
				});
			  });
			});
		</script>
	</body>
</html>
